package com.xhx.shardingjdbc.other;

import com.mysql.cj.jdbc.Driver;

import java.sql.*;

/**
 * @program: xh-learn-record
 * @description:
 * @author: sch
 * @create: 2023-02-28 11:26
 **/
public class BaterCreateTable {
    public static void main(String[] args) throws SQLException {
        String url = "jdbc:mysql://localhost:3307/db0";
        String username = "root";
        String password = "root";

        //注册驱动
        DriverManager.deregisterDriver(new Driver());

        //创建连接
        Connection conn = DriverManager.getConnection(url, username, password);

        //创建statement,执行sql
        Statement stmt = conn.createStatement();
        //创建表
        createTable(stmt);

        conn.close();
        stmt.close();
        System.out.println("main over");
    }


    private static void createTable(Statement stmt) throws SQLException {
//        for (int i = 0; i < 3; i++) {
////            String sql = "create table book_" + i + "(id int,count int,name varchar(32));";
//            String sql = "create table user_info" + i + "(id int,name varchar(32),age int,skill varchar(32),evaluate varchar(128),fraction bigint);";
//            stmt.execute(sql);
//        }

        String sql = "create table t2(id int auto_increment,name varchar(32),age int,skill varchar(32),evaluate varchar(128),fraction bigint,constraint table_name_pk\n" +
                "\t\tprimary key (id));";
        stmt.execute(sql);
    }
}
